package text.traversal;

import text.Text;

public class ComputeProbaOccurence implements ITextTraversal
{
	public final static String PROBA_OCCURENCE = "ProbaOccurence";
	
	private double coeffLaplace;
	
	public ComputeProbaOccurence(double coeffLaplace)
	{
		this.coeffLaplace = coeffLaplace;
	}
	
	public void traversal(String word, Text text)
	{	
		double textOccurenceCount = text.getOccurenceCount(word);
		double probaOccurence = (textOccurenceCount + coeffLaplace) / (text.getWordOccurenceSum() + text.getWordCount() * coeffLaplace);

		text.addInfo(PROBA_OCCURENCE, word, probaOccurence);
	}
}
